import axios from '@/libs/axios.js'
import baseUrl from './index'
import qs from 'qs'
let jsonHeaders = {'content-type': 'application/json;charset=UTF-8'}

// 单位人员列表
export const getCompanyData = (params) => {
    return axios({
        url: `${baseUrl}/identity/company/users`,
        method: 'get',
        params:params,
        headers: jsonHeaders,
    })
}

// 单位人员列表带实验组
export const getCompanyUsersHasGroup = (params) => {
    return axios({
        url: `${baseUrl}/identity/company/usersAndGroup`,
        method: 'get',
        params:params,
        headers: jsonHeaders,
    })
}

// 实验组列表
export const getExperiData = (params) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups`,
        method: 'get',
        params:params,
        headers: jsonHeaders,
    })
}

// 实验组列表列表带人员列表
export const getGroupHasUsers = (params) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/haveUsers`,
        method: 'get',
        params:params,
        headers: jsonHeaders,
    })
}

// 验证用户名是否已存在
export const verifyUserName = (username) => {
    return axios({
        url: `${baseUrl}/identity/anonymity/assess/username?username=${username}`,
        method: 'get',
        headers: jsonHeaders,
    })
}
// 创建者员提交
export const createUser = (params,data) => {
    return axios({
        url: `${baseUrl}/identity/company/users`,
        method: 'post',
        params:params,
        data:JSON.stringify(data),
        headers: jsonHeaders,
    })
}
// 删除人员
export const delCompanyMember = (id) => {
    return axios({
        url: `${baseUrl}/identity/company/users/${id}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
// 批量删除人员
export const deleteListUser = (id) => {
    return axios({
        url: `${baseUrl}/identity/company/users/${id}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
//批量删除实验组
export const deleteGroups = (id) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${id}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
// 创建课件用户组
export const creatGroup = (data) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups`,
        method: 'post',
        data: JSON.stringify(data),
        headers: jsonHeaders,
    })
}
// 修改课件用户组
export const reGroup = (id,data) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${id}`,
        method: 'put',
        data: JSON.stringify(data),
        headers: jsonHeaders,
    })
}
// 解散课件用户组
export const delGroup = (id) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${id}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
// 查询课件用户组的成员
export const getGroupMembers = (id) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${id}/users`,
        method: 'get',
        headers: jsonHeaders,
    })
}
// 查询单位内的课件人员
export const getExperOfCompany = (params) => {
    return axios({
        url: `${baseUrl}/identity/company/users`,
        method: 'get',
        params:params,
        headers: jsonHeaders,
    })
}
// 向实验组添加成员
export const addMembersForGroup = (id,data) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${id}/users`,
        method: 'post',
        data:JSON.stringify(data),
        headers: jsonHeaders,
    })
}
// 移除组内成员
export const removeMemberByGroup = (params) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${params.groupId}/users/${params.userId}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
// 批量移除组内成员
export const batchRemoveMemberByGroup = (groupId, ids) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${groupId}/users`,
        method: 'delete',
        headers: jsonHeaders,
        data: ids
    })
}
// 创建邀请
export const creatInvaita = (groupId,data) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${groupId}/invite`,
        method: 'post',
        data:JSON.stringify(data),
        headers: jsonHeaders,
    })
}
// 查看实验组的申请
export const checkApply = (id) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${id}/apply`,
        method: 'get',
        headers: jsonHeaders,
    })
}
// 同意申请
export const agreeApply = (params) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${params.groupId}/confirm?applyId=${params.applyId}`,
        method: 'post',
        data:JSON.stringify(params.data),
        headers: jsonHeaders,
    })
}
//  拒绝加入
export const refuseApply = (params) => {
    return axios({
        url: `${baseUrl}/identity/experimenterGroups/${params.groupId}/reject?applyId=${params.applyId}`,
        method: 'post',
        headers: jsonHeaders,
    })
}
//  重置课件人员密码
export const resetPwd = (id) => {
    return axios({
        url: `${baseUrl}/identity/company/users/${id}/password/init`,
        method: 'patch',
        headers: jsonHeaders,
    })
}
//  密码黑名单
export const getPwdBlackList = () => {
    return axios({
        url: `${baseUrl}/identity/anonymity/password/blacklist`,
        method: 'get',
        headers: jsonHeaders,
    })
}

//导出用户
export const exportUsers = params => {
  return axios({
    url: `${baseUrl}/identity/company/users/export`,
    method: 'get',
    params:params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    },
    headers:{
        'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
    timeout:0
  })
}

//导出用户 - new
export const exportUsersNew = params => {
  return axios({
    url: `${baseUrl}/identity/company/users/export/new`,
    method: 'post',
    data:params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    },
    headers:{
        'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
  })
}

//导出实验组
export const exportGroups = params => {
  return axios({
    url: `${baseUrl}/identity/experimenterGroups/export`,
    method: 'get',
    params:params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    },
    headers:{
        'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
    timeout:0
  })
}

//导出实验组 - new
export const exportGroupsNew = params => {
  return axios({
    url: `${baseUrl}/identity/experimenterGroups/export/new`,
    method: 'post',
    data:params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    },
    headers:{
        'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
  })
}

//  近一周使用最多接口TOP10
export const getUseInterFaceTen = (params) => {
    return axios({
        url: `${baseUrl}/openrange-log/log/oneBestManyApi?dateRange=${params}`,
        method: 'get',
        headers: jsonHeaders,
    })
}

//  近一周使用接口最多的人员TOP10
export const getUseInterByUserTen = (params) => {
    return axios({
        url: `${baseUrl}/openrange-log/log/oneBestManyUser?dateRange=${params}`,
        method: 'get',
        headers: jsonHeaders,
    })
}

// 日志类型列表菜单
export const getLogMenus = () => {
    return axios({
        url: `${baseUrl}/openrange-log/log/uri/map`,
        method: 'get',
        headers:jsonHeaders
    })
}